Skip to content

Hash paths relative to the workspace into metadata. #14953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Dirbaio
Copy link
Contributor

@Dirbaio Dirbaio commented Dec 18, 2024

Currently Cargo hashes the relative path if it's under the workspace root,
or absolute if it isn't.

This causes non-reproducibility problems when using dependencies like path = "../foo"
that point to crates outside the workspace (or when not using a workspace at all).

This PR fixes the problem by making all paths relative to the workspace root, not
just paths under it.

Fixes #13586

@rustbot
Copy link
Collaborator

rustbot commented Dec 18, 2024

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 18, 2024
@Dirbaio
Copy link
Contributor Author

Dirbaio commented Dec 18, 2024

r? @weihanglo

this is related to #14951 , also #13586 (comment)

@rustbot rustbot assigned weihanglo and unassigned ehuss Dec 18, 2024
@ehuss
Copy link
Contributor

ehuss commented Dec 18, 2024

Can we make sure this has a test? I'm not sure if the intent here is to ensure it stays consistent if the tree is moved, perhaps just a freshness test would suffice?

@weihanglo
Copy link
Member

@Dirbaio are you still interested in this. We might need a test as mentioned above.

I'll mark this as draft temporarily. When ready, feel free to tell @rustbot ready.

@weihanglo weihanglo marked this pull request as draft August 17, 2025 19:28
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 17, 2025
@Dirbaio
Copy link
Contributor Author

Dirbaio commented Aug 19, 2025

I'm not sure if we want this change. It fixes hash instability when you move the workspace and a path dep outside the workspace together, but it creates a new instability when you move the workspace only.

The former happens if you refer to another crate by relative path, typically inside the same repo, but aren't using a workspace. The latter happens if you refer to some crate by absolute path, for example if they're separate repos or the source is installed "system-wide" somehow.

So it depends on which scenario we think is more likely. I've personally ran into the former but not the latter, but that's only one data point.

If you guys agree it's better to always use relative paths I'll rebase this PR and add a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not reproducible when a project is copied to another directory
4 participants